package yja.gzw.app.fragmentview


import android.content.Context
import android.content.Intent
import android.text.Editable
import android.text.TextWatcher
import android.text.method.PasswordTransformationMethod
import yja.gzw.app.R
import yja.gzw.app.activity.WangjimmActivity
import yja.gzw.app.base.BaseFragment
import yja.gzw.app.databinding.FragmentZhanghaoBinding

import yja.gzw.app.model.UserData
import yja.gzw.app.viewmodel.Mainviewmodel
import yja.gzw.app.window.Chicun

class ZhanghaoFragmen :BaseFragment<Mainviewmodel, FragmentZhanghaoBinding> (R.layout.fragment_zhanghao){
    val chicun= Chicun()
    private var issee=true
    private var onDataListener: OnInputDataListener? = null
  //  todo 开眼睛 chakanshu
  //   todo 闭眼 yanjingguan
    override fun onAttach(context: Context) {
        super.onAttach(context)
        if (context is OnInputDataListener) {
            onDataListener = context
        }
    }
    override fun onDetach() {
        super.onDetach()
        onDataListener = null
    }

    override fun initView() {
        chicun.chicun(binding.emilName,UserData.kuan,50)
        chicun.chicunwai(binding.emilName,20,20,20,0)
        chicun.chicun(binding.buju,UserData.kuan,50)
        chicun.chicunwai(binding.buju,20,20,20,0)
        chicun.chicun(binding.emilPaw,UserData.kuan,50)
        chicun.chicunwai(binding.yanjing,-40,0,0,0)

        chicun.chicunwai(binding.wenghao,0,0,3,0)

        binding.wangjimima.setOnClickListener {
            val intent = Intent(context,WangjimmActivity::class.java)
            startActivity(intent)
        }
        binding.emilPaw.transformationMethod = PasswordTransformationMethod.getInstance()

        binding.yanjing.setOnClickListener {
            if(issee){
                binding.yanjing.setImageResource(R.mipmap.chakanshu)
                binding.emilPaw.transformationMethod = null // 密码框内容设为可见

                issee=!issee
            }else{
                binding.yanjing.setImageResource(R.mipmap.yanjingguan)
                binding.emilPaw.transformationMethod = PasswordTransformationMethod.getInstance() // 密码框内容设为不可见

                issee=!issee
            }



        }



        binding.emilName.addTextChangedListener(object : TextWatcher {
            override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
                // 可以在这里处理文本变化前的逻辑
            }

            override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
                // 可以在这里处理文本变化时的逻辑
            }

            override fun afterTextChanged(s: Editable?) {
                val email = binding.emilName.text.toString()
                val password = binding.emilPaw.text.toString()
                onDataListener?.onInputData(email, password)
            }
        })


        binding.emilPaw.addTextChangedListener(object : TextWatcher {
            override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
                // 可以在这里处理文本变化前的逻辑
            }

            override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
                // 可以在这里处理文本变化时的逻辑
            }

            override fun afterTextChanged(s: Editable?) {
                val email = binding.emilName.text.toString()
                val password = binding.emilPaw.text.toString()
                onDataListener?.onInputData(email, password)
            }
        })






    }

    override fun dataObservese() {


    }


}
interface OnInputDataListener {
    fun onInputData(email: String, password: String)
}
